from django.shortcuts import render

# Create your views here.


from fdfs_client.client import Fdfs_client
#
# client = Fdfs_client('utils/fdfs/client.conf')
# client.upload_by_file('/home/python/Desktop/1.jpg')
# """
# {'Uploaded size': '392.00KB', 'Storage IP': '192.168.161.133',
# 'Group name': 'group1', 'Local file name': '/home/python/Desktop/1.jpg',
# 'Remote file_id': 'group1/M00/00/00/wKihhVylvxuACmfnAAYjJ7AYmio663.jpg', 'Status': 'Upload successed.'}
#
# """


from rest_framework.generics import ListAPIView
from goods.models import SKU
from goods.serializers import HotSerializer


class HotSKUAPIView(ListAPIView):
    #热销是不需要分页
    pagination_class = None

    serializer_class = HotSerializer

    def get_queryset(self):

        category_id = self.kwargs['category_id']

        return SKU.objects.filter(category_id=category_id).order_by('-sales')[:2]


from rest_framework.filters import OrderingFilter
from rest_framework.pagination import PageNumberPagination

# class Pageination(PageNumberPagination):
#
#     page_size = 5
#     page_size_query_param = 'page_size'


class SKUAPIView(ListAPIView):

    serializer_class = HotSerializer

    filter_backends = [OrderingFilter]
    ordering_fields = ['sales', 'price', 'create_time']

    # pagination_class = Pageination

    def get_queryset(self):
        category_id = self.kwargs['category_id']

        return SKU.objects.filter(category_id=category_id)


def generic_list():
    pass


from .serializers import SKUIndexSerializer
from drf_haystack.viewsets import HaystackViewSet


class SKUSearchViewSet(HaystackViewSet):

    index_models = [SKU]

    serializer_class = SKUIndexSerializer
